package java_1_17.object_test;

import java.util.Arrays;

class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    public boolean equals(Object obj){
        //当前对象和传入的obj比，1.先判空
        if(obj==null){
            return false;
        }
        //2.判断obj是否就是自己
        if(obj==this){
            return true;
        }
        //3.判断是否是student类的对象//sout(stu.equals(stu1))时隐藏向上转型Object object=stu1;
        //eg:stu.equals("wssw");的wssw不是Student类对象
        if(!(obj instanceof Student)){
            return false;
        }
        //4.此时obj一定是Student类的对象而且与当前对象不是一个地址
        //向下转型还原为Student，比较当前对象的属性和传入对象的属性
        Student stu=(Student) obj;
        return this.name.equals(stu.name)&&this.age==stu.age;

    }
}
interface IMessage{
    void printMsg();
}
class MessageImpl implements IMessage{
    @Override
    public void printMsg() {
        System.out.println("回家");
    }
}
public class ObjectTest {
    public static void main(String[] args) {
//        Student student=new Student("人",18);
//        Student student1=new Student("人",18);
//        Boolean a=student.equals(student1);
//        System.out.println(a);
        //数组引用
        int[] data={1,2,3,4,5,6,7};
        //接口引用
        IMessage msg=new MessageImpl();
        Object obj1=data;
        Object obj2=msg;
        int[] ret=(int[])obj1;
        IMessage test=(IMessage)obj2;
        System.out.println(Arrays.toString(ret));
        test.printMsg();
    }
}
